package com.shop.config;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author yinxing
 * @date 2022-08-30
 */
@Component
@Slf4j
public class ShopDeadMqConfig {

    @RabbitListener(queues = "${shop.dead-queue}")
    public void receiveMessage(Message message , Channel channel,@Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException {
        String msg= new String(message.getBody());
        log.info("==========shop死信接收到消息:{}=================",msg);
        channel.basicAck(deliveryTag,false);
    }


}
